<%@ page pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<isperp:incidentView>

	<jsp:body> 
	
	 <jsp:include page="step1view.jsp"></jsp:include> 
			
	 <form:form id="incidentHandleForm" commandName="model"
			cssClass="validate" action="incident/incident/save">
            <form:hidden path="id" />
		
<jsp:include page="step2ForEg.jsp"></jsp:include>

		 
			<div id="handerInfoDiv" class="box no-border">
				<div class="header">
					<h3>诊断和解决信息</h3>
				</div> 
					<table class="form-table">
					    <tr>
							<td class="td1">故障定位：</td>
							<td class="td2" colspan="3"><form:hidden
								path="faultlocationId" /> <isperp:treeSelector width="500"
								displayValueCssStyle="width:249px"
								url="incident/faultLocation/getTree"
								id="icdfaultlocationSelector" name="faultlocationName"
								displayValue="${model.faultlocationName }"
								valueControlId="faultlocationId"></isperp:treeSelector>
						</td>
						</tr>
						
					 
						
						<tr>
							<td class="td1">原因分析：</td>
							<td class="td2" colspan="3"><form:textarea
								path="reasonAnalyze" cssClass="required" />
						</td>
						</tr>

						<tr>
							<td class="td1">解决方案：</td>
							<td class="td2" colspan="3"><form:textarea path="solution"
								cssClass="required" />
							</td>
						</tr>
						<tr>
							<td class="td1">处理过程：</td>
							<td class="td2" colspan="3"><form:textarea
								path="handleProcess" />
						</td>
						</tr>
						<tr>
							<td class="td1">解决方式：</td>
							<td class="td2"><form:select path="solutionWay"
								items="${solutionWays}" itemLabel="name" itemValue="name"
								cssClass="required" />
							</td>
							<td class="td1">解决阶段：</td>
							<td class="td2"><form:select path="solutionStage"
								items="${solutionStages}" itemLabel="name" itemValue="name"
								cssClass="required" />
							</td>
						</tr>
					 
						<tr>
							<td class="td1">解决时间：</td>
							<td class="td2" colspan="3"><form:input path="solvedDate"
								type="datetime" cssClass="required" />
							</td>
						</tr>
						

					</table>
					
				
			 </div>
<div class="header">
	<h3>关闭信息</h3>
</div>
<table class="form-table">
	<c:choose>

		<c:when test="${model.areFeedback eq true }">
			<tr>
				<td class="td1">是否客户评价：</td>
				<td class="td2"><form:checkbox path="areFeedback"
									disabled="true" />
							</td>
			</tr>

			<tr>
				<td class="td1">关闭码：</td>
				<td class="td2" colspan="3"><isperp:dictSelector
									dataWidth="260px" typeCode="INCIDENT_CLOSECODE"
									name="closeCode" id="txtCloseCode"
									selectedValue="${model.closeCode }" hasEmptyValue="false"
									dictCssClass="required"></isperp:dictSelector>
				</td>
			</tr>
			<tr>
				<td class="td1">满意度：</td>
				<td class="td2"><form:radiobuttons path="satisfaction"
									cssClass="required" items="${satisfications}" itemLabel="name"
									itemValue="code" />&nbsp;&nbsp;(5分为满分)<label class="required"></label>
				</td>
			</tr>
			<tr>
				<td class="td1">客户意见：</td>
				<td class="td2"><form:textarea path="customerOpinion"
									disabled="true" />
							</td>
			</tr>
		</c:when>
		<c:otherwise>
			<tr>
				<td class="td1">关闭码：</td>
				<td class="td2" colspan="3"><isperp:dictSelector
									dataWidth="260px" typeCode="INCIDENT_CLOSECODE"
									name="closeCode" id="txtCloseCode" hasEmptyValue="false"
									dictCssClass="required"></isperp:dictSelector>
				</td>
			</tr>
			<tr>
				<td class="td1">满意度：</td>
				<td class="td2"><form:radiobuttons path="satisfaction"
									cssClass="required" items="${satisfications}" itemLabel="name"
									itemValue="code" />&nbsp;&nbsp;(5分为满分)<label class="required"></label>
				</td>
			</tr>
			<tr>
				<td class="td1">客户意见</td>
				<td class="td2"><form:textarea path="customerOpinion" />
							</td>
			</tr>
			<tr>
			               <td class="td1">附件：</td>
			                   <td class="td2" colspan="3"><isperp:uploader
									sourceId="${model.id }" id="incidentFiles1"></isperp:uploader>
			                    </td>
		                </tr>
		</c:otherwise>
	</c:choose>
</table>
	</form:form>
	</jsp:body>
</isperp:incidentView>

<isperp:buttonList>

	<%-- 	<c:choose>
		<c:when test="${empty model.responseDate }">
			<button class="nui-mainbtn" onclick="dealIncident('3');">响应</button>
		</c:when>
		<c:otherwise>
			<c:if test="${empty model.arrivalDate}">
				<button class="nui-mainbtn" onclick="dealIncident('4');">到场</button>
			</c:if>
		</c:otherwise>

	</c:choose> --%>

	<isperp:processButtons processKey="incidentProcess" viewOnly="false"
		beforeSubmit="function(name){return checkTask(name);}"
		formId="incidentHandleForm" processId="${model.processId }"
		businessKey="${model.id }"></isperp:processButtons>
	<button
		onclick="isperp.openDialog({contentUrl:'ReportServer?reportlet=incident/cpt_incident_print_pd.cpt&op=write&incident_id=${model.id}'})">打印事件单</button>

</isperp:buttonList>



<script type="text/javascript">
	var result = false;
	function checkTask(name) {
		if (name == "处理完成" && result == false) {
			var id = "${model.id}";
			var unPassNum = 0;
			var unPassNumSpOut = 0;
			var unPassNumSpBack = 0;
			var passNumSpOut = 0;
			var NumSpBack = 0;
			var errMessage = "";

			if ($("#incidentHandleForm").valid() == false) {
				return false;
			}
			var relationProRows = $("#processRelationGrid").jqGrid("getRowData");
			if (relationProRows.length < 1) {
				return true;
			} else {
				jQuery(relationProRows).each(function() {
					if (this.key_ == "taskProcess") {
						if (this.status != "解决" && this.status != "已关闭" && this.status != undefined && this.status != "")
							unPassNum = unPassNum + 1;
					}
					if (this.key_ == "sparepartOutProcess") {
						if (this.status != "已关闭" && this.status != undefined && this.status != "")
							unPassNumSpOut = unPassNumSpOut + 1;
						else if (this.status == "已关闭") {
							passNumSpOut = passNumSpOut + 1;
						}
					}
					if (this.key_ == "sparepartBackProcess") {
						NumSpBack = NumSpBack + 1;
						if (this.status != "已关闭" && this.status != undefined && this.status != "")
							unPassNumSpBack = unPassNumSpBack + 1;
					}
				});
				if (unPassNum > 0) {
					errMessage += "有" + unPassNum + "件未解决的工作单。<br>。";
				} else if (unPassNumSpOut > 0) {
					errMessage += "有关联的出库流程【未关闭】<br>";

				} else if (unPassNumSpBack > 0) {
					errMessage += "有关联的归还流程【未关闭】<br>";
				} else if (passNumSpOut > 0 && NumSpBack == 0) {
					errMessage += "有关联已关闭的领用流程，但没有关联的【归还流程】<br>";
				} else {
					return true;
				}
				if (errMessage != "") {
					isperp.confirmAlert(errMessage + "是否提交？", {
						yes : function() {
							//提交表单
							result = true;
							$("[data-name='处理完成']").click();

						}
					});
				}
			}

			return result;
		} else {
			return true;
		}

	}

	//退回
	function backval() {
		if ($("#backOpnion").val() == "") {

			isperp.isValidate = false;
			isperp.alert("请填写退回原因");
			$("#backOpnion").focus();
			return false;
		} else {
			isperp.isValidate = true;
			return true;
		}
	}

	//退回
	function zhuanpaival() {
		if ($("#supporterSelect").val() == "") {
			isperp.alert("支持人员不能为空");
			$("#supporterSelect").focus();
			isperp.isValidate = false;
			return false;
		} else {
			var rs = confirm("确认要转派给【" + $("#supporterSelect").val() + "】吗");
			isperp.isValidate = rs;
			return rs;
		}
	}

	function dealIncident(type) {
		var id = "${model.id}";

		$.post("incident/incident/deal", {
			id : "${model.id}",
			type : type
		}, function(data) {

			if (data.success) {
				window.location.reload();
			} else {
				isperp.alert(data.data);
			}
		});
	}

	$(function() {

		$("#backOpnion").val("");
	});
</script>